/*
 * Icons credit to WebAppers.com
 */

package view;

import view.calendar.*;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.*;
import view.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;


public class ParentFrame extends JFrame {

	private static final long serialVersionUID = 1245210405639211L;
	private static ParentFrame instance;
	
	/*
	 * the frames components declared here
	 */
	private Container cont;
	
	private JPanel topPanel;
	private JPanel calendarPanel;

	private LargeLabel lastEntryLabel;
	
	private JSeparator middleSeparator;
	private JSeparator bottomPanelSeparator;
	private JTextField telstraClearText;
	private JTextField vodafoneText;
	private JTextField groceryText;
	private JTextField internetText;
	private JTextField electricityText;
	private JTextField miscText;
	private JTextField creditCardText;
	private JTextField nationalBankText;
	private JLabel balanceLabel;
	private JLabel inLabel;
	private JLabel totalExpensesLabel;
	private JLabel savedLabel;
	private JTextArea CommentsTextArea;
	private JButton createRecordButton;
	private JButton editThisDateButton;
	private JButton clearThisDateButton;
	
	private JXMonthView calendar;
	
	
	/*
	 * end components declaration
	 */
	
	private ParentFrame() {
		super("Churvaloo");
		setIconImage(Toolkit.getDefaultToolkit().getImage(ParentFrame.class.getResource("/Resources/icon.png")));
		setSize(787, 477);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		setLocationByPlatform(true);
		initComponents();
	}
	
	/**
	 * All components of ParentFrame is initialized here
	 */
	public void initComponents() {
		cont = getContentPane();
		cont.setLayout(null);
		cont.add(getTopPanel());
		cont.add(getMiddleSeparator());
		cont.add(getCalendarPanel());
		cont.add(getBottomPanelSeparator());
		cont.add(getLastEntryLabel());
		
		JPanel balancePanel = new JPanel();
		balancePanel.setBorder(new TitledBorder(null, "Balance", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		balancePanel.setBounds(15, 284, 202, 62);
		getContentPane().add(balancePanel);
		balancePanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		
		balanceLabel = new JLabel("$0.00");
		balanceLabel.setFont(new Font("Segoe UI", Font.BOLD, 18));
		balancePanel.add(balanceLabel);
		
		JPanel InPanel = new JPanel();
		InPanel.setBorder(new TitledBorder(null, "In", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		InPanel.setBounds(268, 119, 253, 53);
		getContentPane().add(InPanel);
		InPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		
		inLabel = new JLabel("$0.00");
		inLabel.setFont(new Font("Segoe UI", Font.BOLD, 18));
		InPanel.add(inLabel);
		
		JPanel totalExpensesPanel = new JPanel();
		totalExpensesPanel.setBorder(new TitledBorder(null, "Total Expenses", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		totalExpensesPanel.setBounds(268, 171, 253, 53);
		getContentPane().add(totalExpensesPanel);
		totalExpensesPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		
		totalExpensesLabel = new JLabel("$0.00");
		totalExpensesLabel.setFont(new Font("Segoe UI", Font.BOLD, 18));
		totalExpensesPanel.add(totalExpensesLabel);
		
		JPanel savedPanel = new JPanel();
		savedPanel.setBorder(new TitledBorder(null, "Saved", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		savedPanel.setBounds(268, 221, 253, 53);
		getContentPane().add(savedPanel);
		savedPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		
		savedLabel = new JLabel("$0.00");
		savedLabel.setFont(new Font("Segoe UI", Font.BOLD, 18));
		savedPanel.add(savedLabel);
		
		JLabel commentsLabel_1 = new JLabel("Comments");
		commentsLabel_1.setBounds(268, 285, 57, 14);
		getContentPane().add(commentsLabel_1);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(319, 292, 202, 18);
		getContentPane().add(separator);
		
		JScrollPane commentsScrollPane = new JScrollPane();
		commentsScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		commentsScrollPane.setBounds(268, 310, 253, 125);
		getContentPane().add(commentsScrollPane);
		
		CommentsTextArea = new JTextArea();
		commentsScrollPane.setViewportView(CommentsTextArea);
		CommentsTextArea.setFont(new Font("Segoe UI", Font.PLAIN, 12));
		CommentsTextArea.setText("Churvaloo\r\n");
		CommentsTextArea.setEditable(false);
		
		JPanel billsPanel = new JPanel();
		billsPanel.setBorder(new TitledBorder(null, "Bills", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		billsPanel.setBounds(531, 121, 240, 317);
		getContentPane().add(billsPanel);
		billsPanel.setLayout(null);
		
		JLabel lblTelstraclear = new JLabel("TelstraClear");
		lblTelstraclear.setBounds(20, 25, 70, 23);
		billsPanel.add(lblTelstraclear);
		
		telstraClearText = new JTextField();
		telstraClearText.setEditable(false);
		telstraClearText.setBackground(Color.WHITE);
		telstraClearText.setBounds(100, 24, 134, 25);
		billsPanel.add(telstraClearText);
		telstraClearText.setColumns(10);
		
		vodafoneText = new JTextField();
		vodafoneText.setEditable(false);
		vodafoneText.setBackground(Color.WHITE);
		vodafoneText.setColumns(10);
		vodafoneText.setBounds(100, 59, 134, 25);
		billsPanel.add(vodafoneText);
		
		JLabel lblVodafone = new JLabel("Vodafone");
		lblVodafone.setLabelFor(vodafoneText);
		lblVodafone.setBounds(20, 60, 70, 23);
		billsPanel.add(lblVodafone);
		
		groceryText = new JTextField();
		groceryText.setEditable(false);
		groceryText.setBackground(Color.WHITE);
		groceryText.setColumns(10);
		groceryText.setBounds(100, 95, 134, 25);
		billsPanel.add(groceryText);
		
		JLabel lblGrocery = new JLabel("Grocery");
		lblGrocery.setLabelFor(groceryText);
		lblGrocery.setBounds(20, 96, 70, 23);
		billsPanel.add(lblGrocery);
		
		internetText = new JTextField();
		internetText.setEditable(false);
		internetText.setBackground(Color.WHITE);
		internetText.setColumns(10);
		internetText.setBounds(100, 131, 134, 25);
		billsPanel.add(internetText);
		
		JLabel lblInternet = new JLabel("Internet");
		lblInternet.setBounds(20, 132, 70, 23);
		billsPanel.add(lblInternet);
		
		electricityText = new JTextField();
		electricityText.setEditable(false);
		electricityText.setBackground(Color.WHITE);
		electricityText.setColumns(10);
		electricityText.setBounds(100, 167, 134, 25);
		billsPanel.add(electricityText);
		
		JLabel lblElectricity = new JLabel("Electricity");
		lblElectricity.setBounds(20, 168, 70, 23);
		billsPanel.add(lblElectricity);
		
		miscText = new JTextField();
		miscText.setEditable(false);
		miscText.setBackground(Color.WHITE);
		miscText.setColumns(10);
		miscText.setBounds(100, 203, 134, 25);
		billsPanel.add(miscText);
		
		JLabel lblMisc = new JLabel("Misc");
		lblMisc.setBounds(20, 204, 70, 23);
		billsPanel.add(lblMisc);
		
		creditCardText = new JTextField();
		creditCardText.setEditable(false);
		creditCardText.setBackground(Color.WHITE);
		creditCardText.setColumns(10);
		creditCardText.setBounds(100, 239, 134, 25);
		billsPanel.add(creditCardText);
		
		JLabel lblCreditCard = new JLabel("Credit Card");
		lblCreditCard.setBounds(20, 240, 70, 23);
		billsPanel.add(lblCreditCard);
		
		nationalBankText = new JTextField();
		nationalBankText.setEditable(false);
		nationalBankText.setBackground(Color.WHITE);
		nationalBankText.setColumns(10);
		nationalBankText.setBounds(100, 275, 134, 25);
		billsPanel.add(nationalBankText);
		
		JLabel lblNationalBank = new JLabel("National Bank");
		lblNationalBank.setBounds(20, 276, 70, 23);
		billsPanel.add(lblNationalBank);
		getCalendarPanel().setLayout(null);
		
		getCalendarPanel().add(getCalendar());
	}
	
	public static ParentFrame getInstance() {
		if (instance == null) {
			instance = new ParentFrame();
		}
		return instance;
	}
	
	public JPanel getTopPanel() {
		if (topPanel == null) {
			topPanel = new JPanel();
			topPanel.setBackground(Color.WHITE);
			topPanel.setBounds(0, 0, 780, 80);
			topPanel.setLayout(null);
			
			createRecordButton = new JButton("Create Record");
			createRecordButton.setHorizontalAlignment(SwingConstants.LEFT);
			createRecordButton.setIcon(new ImageIcon(ParentFrame.class.getResource("/Resources/add.png")));
			createRecordButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				}
			});
			createRecordButton.setBounds(10, 11, 155, 58);
			topPanel.add(createRecordButton);
			
			editThisDateButton = new JButton("Edit this date");
			editThisDateButton.setIcon(new ImageIcon(ParentFrame.class.getResource("/Resources/modify.png")));
			editThisDateButton.setBounds(175, 11, 155, 58);
			topPanel.add(editThisDateButton);
			
			clearThisDateButton = new JButton("Clear this date");
			clearThisDateButton.setIcon(new ImageIcon(ParentFrame.class.getResource("/Resources/delete.png")));
			clearThisDateButton.setBounds(340, 11, 155, 58);
			topPanel.add(clearThisDateButton);
		}
		
		return topPanel;
	}

	public JSeparator getMiddleSeparator() {
		if (middleSeparator == null) {
			middleSeparator = new JSeparator();
			middleSeparator.setBounds(0, 80, 780, 1);
		}
		return middleSeparator;
	}
	
	public JPanel getCalendarPanel() {
		if (calendarPanel == null) {
			calendarPanel = new JPanel();
			calendarPanel.setBounds(15, 95, 231, 178);
		}
		return calendarPanel;
	}
	
	public JSeparator getBottomPanelSeparator() {
		if (bottomPanelSeparator == null) {
			bottomPanelSeparator = new JSeparator(SwingConstants.VERTICAL);
			bottomPanelSeparator.setBounds(256, 91, 2, 340);
		}
		return bottomPanelSeparator;
	}
	
	public LargeLabel getLastEntryLabel() {
		if (lastEntryLabel == null) {
			lastEntryLabel = new LargeLabel("Last Entry: May 5, 2011");
			lastEntryLabel.setBounds(268, 91, 450, 18);
		}
		return lastEntryLabel;
	}
	
	public JXMonthView getCalendar() {
		if (calendar == null) {
			calendar = new JXMonthView();
			calendar.setBounds(0, 0, 231, 178);
			calendar.setFirstDayOfWeek(2);
			calendar.setTraversable(true);
		}
		return calendar;
	}
	
	public JLabel getBalanceLabel() {
		return balanceLabel;
	}
	public JLabel getInLabel() {
		return inLabel;
	}
	public JLabel getTotalExpensesLabel() {
		return totalExpensesLabel;
	}
	public JLabel getSavedLabel() {
		return savedLabel;
	}
	public JTextArea getCommentsTextArea() {
		return CommentsTextArea;
	}
	public JTextField getNationalBankText() {
		return nationalBankText;
	}
	public JTextField getCreditCardText() {
		return creditCardText;
	}
	public JTextField getMiscText() {
		return miscText;
	}
	public JTextField getElectricityText() {
		return electricityText;
	}
	public JTextField getInternetText() {
		return internetText;
	}
	public JTextField getGroceryText() {
		return groceryText;
	}
	public JTextField getVodafoneText() {
		return vodafoneText;
	}
	public JTextField getTelstraClearText() {
		return telstraClearText;
	}
	public JButton getCreateRecordButton() {
		return createRecordButton;
	}
	public JButton getEditThisDateButton() {
		return editThisDateButton;
	}
	public JButton getClearThisDateButton() {
		return clearThisDateButton;
	}
}
